import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:part_time_job_pro/pages/message/logic.dart';

import '../../common/style/color.dart';
import '../../common/style/theme.dart';

class MessagePage extends StatelessWidget {
  MessagePage({Key? key}) : super(key: key);

  //路由地址
  static const String routeName = "/message";
  final logic = Get.find<MessageLogic>();
  final state = Get.find<MessageLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: AppColor.norWhite01Color,
        appBar: AppBar(
          backgroundColor: AppColor.norWhite01Color,
          actions: [
            InkWell(
              onTap: () {},
              child: Container(
                padding: EdgeInsets.all(10.r),
                child: const Text(
                  "面试安排",
                  style: AppTheme.actionTitleStyle,
                ),
              ),
            )
          ],
          elevation: 0,
          title: const Text(
            "消息",
            style: AppTheme.appBarStyle,
          ),
        ),
        body: SafeArea(
          child: CustomScrollView(slivers: [
            SliverPersistentHeader(
              delegate: MyHeaderDelegate(),
              pinned: true,
            ),
            SliverList.builder(
              itemCount: 30,
              itemBuilder: (context, index) {
                return ListTile(title: Text('Item $index'));
              },
            ),
            // 添加底部安全区域
            // SliverPadding(
            //   padding: EdgeInsets.only(bottom: MediaQuery.of(context).padding.bottom),
            // ),
          ]),
        ));
  }
}

class MyHeaderDelegate extends SliverPersistentHeaderDelegate {
  @override
  Widget build(
      BuildContext context, double shrinkOffset, bool overlapsContent) {
    return SizedBox(
        height: shrinkOffset < maxExtent ? maxExtent - shrinkOffset : maxExtent,
        child: Container(
          color: Colors.orangeAccent[100],
          padding: EdgeInsets.all(5.r),
          child: const Row(
            children: [
              Expanded(
                  flex: 4,
                  child: Text(
                    "随时随地了解最新招聘进度和报名情况",
                    style: AppTheme.actionTitleStyle,
                  )),
              Expanded(
                  flex: 1,
                  child: Text(
                    "去绑定",
                    style: AppTheme.textLinkStyle,
                  ))
            ],
          ),
        ));
  }

  @override
  double get maxExtent => 32.2; // 最大高度

  @override
  double get minExtent => 32.2; // 最小高度

  @override
  bool shouldRebuild(covariant SliverPersistentHeaderDelegate oldDelegate) {
    return false; // 是否需要重建
  }
}
